$(function(){
	//买家中心
	$('.quick-menu ul li').eq(1).hover(function(){
		$('.quick-menu ul li').eq(1).find("i").removeClass().addClass("fa fa-angle-up");
		$(this).css('background','white');
		$('.Buyer-Center-show').show();
	},function(){
			$('.quick-menu ul li').eq(1).find("i").removeClass().addClass("fa fa-angle-down");
			$(this).css('background','rgb(245,245,245)');
			$('.Buyer-Center-show').hide();
		});
	
	//手机商城
	$('.quick-menu ul li').eq(5).hover(function(){
		$('.quick-menu ul li').eq(5).find("i").removeClass().addClass("fa fa-angle-up");
		$(this).css('background','white');
		$('.quick-menu .Mobile-phone-mall').show();
	},function(){
		$('.quick-menu ul li').eq(5).find("i").removeClass().addClass("fa fa-angle-down");
		$(this).css('background','rgb(245,245,245)');
		$('.quick-menu .Mobile-phone-mall').hide();
	});
	
	//联系客服
	$('.quick-menu ul li').last().hover(function(){
		$('.quick-menu ul li').last().find("i").removeClass().addClass("fa fa-angle-up");
		$(this).css('background','white');
		$('.quick-menu .Notescontact').show();
	},function(){
		$('.quick-menu ul li').last().find("i").removeClass().addClass("fa fa-angle-down");
		$(this).css('background','rgb(245,245,245)');
		$('.quick-menu .Notescontact').hide();
	});
			//获取cookie
//			var cookieJson = JSON.parse($.cookie('product'));
			
				
			
	angular.module('app', []).controller('firstController',
	function($scope) {
	//					split() 方法用于把一个字符串分割成字符串数组
		var arrText=$.cookie("texts").split(",");
		var arrPrice=$.cookie("price").split(",");
		$scope.Product = [];
		$scope.Product.length = arrText.length;
		console.log(arrText[0])
		for(var i=0;i<arrText.length;i++){
			$scope.Product[i]={
				name: arrText[i],
				quantity: 1,
				price:arrPrice[i]
			}
		}
		
		
		$scope.totalPrice = function() {
			var total = 0;
	
	//						return total;
			angular.forEach($scope.Product, function(item) {
				total += item.quantity * item.price;
			});
			return total;
		}
	
		$scope.totalQuantity = function() {
			var total = 0;
			angular.forEach($scope.Product, function(item) {
				total += parseInt(item.quantity);
			});
			return total;
		}
	
		$scope.remove = function(index) {
			$scope.Product.splice(index, 1);
		}
	
		$scope.removeall = function() {
			var index;
			for(index = $scope.Product.length - 1; index >= 0; index--) {
				$scope.remove(index);
			}
		}
	
		$scope.reduce = function(index) {
			if($scope.Product[index].quantity != 1) {
				$scope.Product[index].quantity--;
			} else {
				var ans = confirm("是否移除该产品？");
				if(ans) {
					$scope.remove(index);
				} else {
					$scope.Product[index].quantity = 1;
				}
			}
		}
	
		$scope.add = function(index) {
			$scope.Product[index].quantity++;
		}
	
		$scope.$watch('Product', function(newValue, oldValue) {
			angular.forEach(newValue, function(item, key) {
				if(item.quantity < 1) {
					var ans = confirm("是否移除该产品？");
					if(ans) {
						$scope.remove(key);
					} else {
						item.quantity = oldValue[key].quantity;
					}
					return;
				}
			});
		}, true);
	
	});
	
		function login(){
			if($.cookie('mobile') && $.cookie('password')){
				$('.zc-login-left').html('<span>欢迎您'+$.cookie("mobile")+'</span>');
				$('.zc-register a').text("退出登录");
			};
		};
		login();
});
